package com.geekcoding.geekoj.entity;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.geekcoding.common.enums.Sex;
import com.geekcoding.geekoj.nums.Role;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Date;

/**
 * 用户
 *
 * @author xiaobai
 * @since 2024/02/25 14:02
 **/

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@TableName("geekoj_user")
public class UserEntity extends BaseEntity{

    private String stuNo;

    private String cellphone;

    private String name;

    private String nickName;

    @EnumValue
    private Sex sex;

    @EnumValue
    private Role role;

    private String password;

    private String salt;

    private String token;

    public void initPwd(){
        this.salt = RandomUtil.randomString(6);
        this.password = SecureUtil.md5(this.stuNo + this.salt);
    }
}
